//
//  MYXRedListHeadCell.m
//  meiyinxiang
//
//  Created by 陈李飞 on 2017/11/22.
//  Copyright © 2017年 hbjApple. All rights reserved.
//

#import "MYXRedListHeadCell.h"
#import "UIImageView+LBBlurredImage.h"
#import "MYXotheruserinfoModel.h"
#import "userinfoModel.h"
#import "UIView+Additions.h"
#import "MYXNIMSessionViewController.h"


#import <objc/runtime.h>
#import <QuartzCore/QuartzCore.h>
#import <Accelerate/Accelerate.h>

@implementation MYXRedListHeadCell

- (void)awakeFromNib {
    [super awakeFromNib];
//    [self fixSDBug];
    // Initialization code
    self.bgImageView.contentMode = UIViewContentModeScaleAspectFill;
   //  方法1,没有blurRadius参数,因为默认是20
    [self.bgImageView setImageToBlur:[UIImage imageNamed:@"cardpanl.jpg"] blurRadius:5 completionBlock:nil];
    self.bgImageView.userInteractionEnabled = YES;
}
- (IBAction)letterButton:(id)sender {
    if ([self.MYXotheruserinfoM.each_follow isEqualToString:@"1"]) {
        NIMSession *session = [NIMSession session:[NSString stringWithFormat:@"abc%@",self.MYXotheruserinfoM.userID] type:NIMSessionTypeP2P];
        MYXNIMSessionViewController *vc = [[MYXNIMSessionViewController alloc] initWithSession:session];
        [[self viewController].navigationController pushViewController:vc animated:YES];
    }else{
        [JXTHUDHelper showHUDText:@"没有相互关注，不能聊天哦～" type:@"error" inView:nil];
    }
}
- (IBAction)fllowButton:(id)sender {
    if (self.fllowB) {
        self.fllowB();
    }
}
- (IBAction)backButton:(id)sender {
      [[self viewController].navigationController popViewControllerAnimated:YES];
}

-(void)setMYXotheruserinfoM:(MYXotheruserinfoModel *)MYXotheruserinfoM{
    _MYXotheruserinfoM = MYXotheruserinfoM;
    self.nameLabel.text = MYXotheruserinfoM.nickname;
    if ([MYXotheruserinfoM.sex isEqualToString:@"1"]) {
        self.sexLabel.image =[UIImage imageNamed:@"nvsheng"];
    }else if ([MYXotheruserinfoM.sex isEqualToString:@"2"]){
        self.sexLabel.image =[UIImage imageNamed:@"nansheng"];
    }else{
        self.sexLabel.image =[UIImage imageNamed:@"nvsheng"];
    }
    if (MYXotheruserinfoM.image) {
        [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:MYXotheruserinfoM.image] placeholderImage:[UIImage imageNamed:@"AppIcon"]];
       [self.bgImageView sd_setImageWithURL:[NSURL URLWithString:MYXotheruserinfoM.image] placeholderImage:[UIImage imageNamed:@"AppIcon"]];
        
//        NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@",MYXotheruserinfoM.image]];
//        
//        NSData *dt = [NSData dataWithContentsOfURL: url];
//        UIImage *image = [[UIImage alloc] initWithData: dt];
        // 方法2,对背景图片进行毛玻璃效果处理,参数blurRadius默认是20,可指定,最后一个参数block回调可为nil
        [self.bgImageView setImageToBlur:self.bgImageView.image blurRadius:15 completionBlock:nil];
        self.bgImageView.userInteractionEnabled = YES;
    }else{
        self.iconImageView.image =[UIImage imageNamed:@"AppIcon"];
    }
    
    if ([self.MYXotheruserinfoM.is_follow isEqualToString:@"1"]) {
        [self.followButton setTitle:@"已关注" forState:UIControlStateNormal];
    }else{
        [self.followButton setTitle:@"+ 关注" forState:UIControlStateNormal];
    }
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
